Skip to content

Fix lexing MacroVar syntax in literal#16779

Open
straight-shoota wants to merge 3 commits intocrystal-lang:masterfrom
straight-shoota:fix/lexer-macro-delimited
Open

Fix lexing MacroVar syntax in literal#16779
straight-shoota wants to merge 3 commits intocrystal-lang:masterfrom
straight-shoota:fix/lexer-macro-delimited

Conversation

@straight-shoota
Copy link
Copy Markdown
Member

@straight-shoota straight-shoota commented Mar 24, 2026

This fixes the behaviour documented in #16778: We should never parse a MacroVar inside a literal.

This patch includes a refactor that simplifies lexing precent literal delimiters significantly with a generalized helper method delimiter_state_for_percent_literal.
Unfortunately, the refactor and bugfix are deeply intertwined and mutually depend on each other. Merging either individually breaks some expectations. So I figure it's easier to commit them as a single change.
Still, the first two commits are refactors, the last one is the actual bug fix.

The significant change is standardized detection and parsing of percent literal delimiters, and the actual parsing for macro tokens happens in a single place. By being able to clearly identify these delimiters, we can strictly separate them from MacroVar syntax.

Depends on #16778

@straight-shoota straight-shoota self-assigned this Mar 24, 2026
@straight-shoota straight-shoota added kind:bug A bug in the code. Does not apply to documentation, specs, etc. topic:compiler:parser labels Mar 24, 2026
@straight-shoota straight-shoota force-pushed the fix/lexer-macro-delimited branch from 27c71a2 to 8e3527d Compare March 25, 2026 09:55
@straight-shoota straight-shoota marked this pull request as ready for review March 25, 2026 10:10
@straight-shoota straight-shoota force-pushed the fix/lexer-macro-delimited branch from 8e3527d to 04ece9f Compare March 25, 2026 10:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

kind:bug A bug in the code. Does not apply to documentation, specs, etc. topic:compiler:parser

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant